home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows5 / xwinc100.zip / CONTRIB-.00 / CONTRIB- / contrib / examples / PEX / multisurf.c < prev    next >
C/C++ Source or Header  |  1991-02-16  |  7KB  |  248 lines

  1. /* $XConsortium: multisurf.c,v 5.1 91/02/16 09:32:26 rws Exp $ */
  2.  
  3. /***********************************************************
  4. Copyright (c) 1991 by Sun Microsystems, Inc. and the X Consortium.
  5.  
  6.                         All Rights Reserved
  7.  
  8. Permission to use, copy, modify, and distribute this software and its 
  9. documentation for any purpose and without fee is hereby granted, 
  10. provided that the above copyright notice appear in all copies and that
  11. both that copyright notice and this permission notice appear in 
  12. supporting documentation, and that the names of Sun Microsystems,
  13. the X Consortium, and MIT not be used in advertising or publicity 
  14. pertaining to distribution of the software without specific, written 
  15. prior permission.  
  16.  
  17. SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 
  18. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT 
  19. SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
  20. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23. SOFTWARE.
  24.  
  25. ******************************************************************/
  26.  
  27. #define PI 3.141592654
  28.  
  29. #include "phigs/phigs.h"
  30. main(argc,argv)
  31.         int argc; char  ** argv;
  32. {
  33.     static Pview_map3 view_map = {
  34.                 { 0.0, 1.0, 0.0, 1.0},
  35.                 { 0.0, .5, 0.5, 1.0, 0.0, 1.0},
  36.                 PTYPE_PARAL,
  37.                 { 0.5, 0.5, -20.0},
  38.                 0.0,
  39.                 0.0,
  40.                 1.0
  41.                   };
  42.  
  43.     static Pview_map3 view_map1 = {
  44.                 { 0.0, 1.0, 0.0, 1.0},
  45.                 { 0.5, 1.0, 0.5, 1.0, 0.0, 1.0},
  46.                 PTYPE_PARAL,
  47.                 { 0.5, 0.5, -20.0},
  48.                 0.0,
  49.                 0.0,
  50.                 1.0
  51.                   };
  52.  
  53.     static Pview_map3 view_map2 = {
  54.                 { 0.0, 1.0, 0.0, 1.0},
  55.                 { 0.0, .5, 0.0, 0.5, 0.0, 1.0},
  56.                 PTYPE_PARAL,
  57.                 { 0.5, 0.5, -20.0},
  58.                 0.0,
  59.                 0.0,
  60.                 1.0
  61.                   };
  62.  
  63.     static Pview_map3 view_map3 = {
  64.                 { 0.0, 1.0, 0.0, 1.0},
  65.                 { 0.5, 1.0, 0.0, 0.5, 0.0, 1.0},
  66.                 PTYPE_PARAL,
  67.                 { 0.5, 0.5, -20.0},
  68.                 0.0,
  69.                 0.0,
  70.                 1.0
  71.                   };
  72.  
  73.     static Ppoint3 vrp = {0., 0., 0 };    /*  origin */
  74.     static Pvec3 vpn = {0.0, 0.0, 1.0 };    /*  view plane normal */
  75.     static Pvec3 vup = {0.0, 1.0, 0.0 };    /*  view up vector */
  76.     
  77.     Pview_rep3 vrep;            /*  view structure */
  78.  
  79.         Pint            err;
  80.         
  81.     Pint         uorder = 4,
  82.             vorder = 4;
  83.     Pfloat_list     uknots,
  84.             vknots;
  85.         static int     unumknots = 20,
  86.                 vnumknots = 20;
  87.         static Pfloat     kpts[] = {  1.0,  2.0,  3.0,  4.0,  5.0, 
  88.                     6.0,  7.0,  8.0,  9.0, 10.0,
  89.                    11.0, 12.0, 13.0, 14.0, 15.0,
  90.                    16.0, 17.0, 18.0, 19.0, 20.0 };
  91.     Prational     rationality = PNON_RATIONAL;
  92.     Ppoint_grid34    grid;
  93.         static Ppoint3     cpts[] = {
  94.  
  95.         0.2,0.5,0.2, 0.4,0.5,0.2, 0.6,0.5,0.2, 0.8,0.5,0.2,
  96.         0.2,0.5,0.4, 0.4,0.7,0.4, 0.6,0.3,0.4, 0.8,0.5,0.4,
  97.         0.2,0.5,0.6, 0.4,0.3,0.6, 0.6,0.7,0.6, 0.8,0.5,0.6,
  98.         0.2,0.5,0.8, 0.4,0.5,0.8, 0.6,0.5,0.8, 0.8,0.5,0.8,
  99.  
  100.                     };
  101.  
  102.     static Ppoint    trim_curve_cpts[] = {
  103.         4.5,    4.25,    1.0,
  104.         4.5,    4.25,    1.0,
  105.         4.625,    4.25,    1.0,
  106.         4.75,    4.375,    1.0,
  107.         4.75,    4.5,    1.0, 
  108.         4.75,    4.625,    1.0,
  109.         4.625,    4.75,    1.0,
  110.         4.5,    4.75,    1.0,
  111.         4.375,    4.75,    1.0,
  112.         4.25,    4.625,    1.0,
  113.         4.25,    4.5,    1.0,
  114.         4.25,    4.375,    1.0,
  115.         4.375,    4.25,    1.0,
  116.         4.5,    4.25,    1.0,
  117.         4.5,    4.25,    1.0
  118.     };
  119.  
  120.     static Pfloat_list trim_knot_list = {
  121.         19,            /* number of knots */
  122.         kpts            /* knot list */
  123.     };
  124.  
  125.     Ppoint_list23    trim_curve_points;
  126.  
  127.     Ptrimcurve_list    trim_curve_list;
  128.  
  129.     Ptrimcurve trim_curves[4];
  130.  
  131.     Pint        curve_approx_type
  132.                 = PCURV_CONSTANT_PARAMETRIC_BETWEEN_KNOTS;
  133.     Pfloat        ucurve_approx_tolerance = 10.0,
  134.             vcurve_approx_tolerance = 10.0;
  135.     Ppoint3        pt;
  136.     Pvec3        shift;
  137.     Pfloat        x_ang, y_ang, z_ang;
  138.     Pvec3        scale;
  139.     Pmatrix3    bldmat;
  140.  
  141.         popen_phigs(NULL,0);
  142.         popen_ws(1,NULL,phigs_ws_type_x_tool);
  143.  
  144.     /* set up views */
  145.     vrep.clip_limit =  view_map.vp;
  146.     vrep.xy_clip = PIND_NO_CLIP;
  147.     vrep.back_clip = PIND_NO_CLIP;
  148.     vrep.front_clip = PIND_NO_CLIP;
  149.     peval_view_ori_matrix3( &vrp, &vpn, &vup, &err, vrep.ori_matrix);
  150.  
  151.     peval_view_map_matrix3(&view_map, &err, vrep.map_matrix);
  152.     pset_view_rep3( 1, 1, &vrep);
  153.  
  154.     peval_view_map_matrix3(&view_map1, &err, vrep.map_matrix);
  155.     pset_view_rep3( 1, 2, &vrep);
  156.  
  157.     peval_view_map_matrix3(&view_map2, &err, vrep.map_matrix);
  158.     pset_view_rep3( 1, 3, &vrep);
  159.  
  160.     peval_view_map_matrix3(&view_map3, &err, vrep.map_matrix);
  161.     pset_view_rep3( 1, 4, &vrep);
  162.  
  163.     /* render path */
  164.         popen_struct(1);
  165.  
  166.     trim_curve_points.num_points = 15;
  167.     trim_curve_points.points.point2d = trim_curve_cpts;
  168.  
  169.     trim_curve_list.num_curves = 1;
  170.     trim_curve_list.curves = trim_curves;
  171.  
  172.     trim_curves[0].visible = PEDGE_ON;        /* visibility */
  173.     trim_curves[0].rationality = PRATIONAL;        /* rational curve */
  174.     trim_curves[0].order = 4;            /* cubic curve */
  175.     trim_curves[0].approx_type = PCURV_WS_DEP;    /* approx type (1) */
  176.     trim_curves[0].approx_val = 1.0;        /* approx tolerance */
  177.     trim_curves[0].knots = trim_knot_list;        /* trim curve knots */
  178.     trim_curves[0].tmin = 4.0; 
  179.     trim_curves[0].tmax = 16.0;            /* parameter range */
  180.     trim_curves[0].cpts = trim_curve_points;    /* control points */
  181.  
  182.         grid.num_points.u_dim = 4;
  183.         grid.num_points.v_dim = 4;
  184.         grid.points.point3d = cpts;
  185.  
  186.     uknots.num_floats = grid.num_points.u_dim + uorder;
  187.     uknots.floats = kpts;
  188.  
  189.     vknots.num_floats = grid.num_points.v_dim + vorder;
  190.     vknots.floats = kpts;
  191.  
  192.     pset_surf_approx(curve_approx_type, 
  193.              ucurve_approx_tolerance, vcurve_approx_tolerance);
  194.  
  195.     pset_int_style(PSTYLE_SOLID);
  196.  
  197.         pset_view_ind(1);
  198.     pset_int_colr_ind(2);
  199.  
  200.     pnuni_bsp_surf( uorder, vorder,
  201.             &uknots, &vknots,
  202.             rationality, 
  203.             &grid, 
  204.             1, &trim_curve_list);
  205.  
  206.     pt.x =  0.5; pt.y = 0.5; pt.z = 0.5;
  207.     shift.delta_x = 0; shift.delta_y = 0; shift.delta_z = 0;
  208.     scale.delta_x = 1.0; scale.delta_y = 1.0; scale.delta_z = 1.0;
  209.     x_ang = 2.0*PI/4.0; y_ang = 0.0; z_ang = 0.0;
  210.  
  211.     pbuild_tran_matrix3(    &pt, &shift, x_ang, y_ang, z_ang,
  212.                 &scale, &err, bldmat);
  213.     pset_local_tran3( bldmat, PTYPE_REPLACE);
  214.  
  215.         pset_view_ind(2);
  216.     pset_int_colr_ind(3);
  217.  
  218.     pnuni_bsp_surf( uorder, vorder,
  219.             &uknots, &vknots,
  220.             rationality, 
  221.             &grid, 
  222.             1, &trim_curve_list);
  223.  
  224.         pset_view_ind(3);
  225.     pset_int_colr_ind(4);
  226.  
  227.     pnuni_bsp_surf( uorder, vorder,
  228.             &uknots, &vknots,
  229.             rationality, 
  230.             &grid, 
  231.             1, &trim_curve_list);
  232.  
  233.         pset_view_ind(4);
  234.     pset_int_colr_ind(5);
  235.  
  236.     pnuni_bsp_surf( uorder, vorder,
  237.             &uknots, &vknots,
  238.             rationality, 
  239.             &grid, 
  240.             1, &trim_curve_list);
  241.  
  242.         ppost_struct(1,1,1.0);
  243.  
  244.         printf("should now see some patches...");
  245.         getchar();
  246. }
  247.  
  248.